// Standard c++ headers
#include <iostream>
#include <fstream>

// Gtkmm headers
#pragma warning(disable:4099)
#include <gtkmm.h>
#pragma warning(default:4099)

// My headers
#include "Logger.h"
#include "RawImage.h"
#include "MainWindow.h"

using namespace RawProject;
using namespace RawProject::GUI;

int main(int argc,char * argv[])
{
	try
	{
	    // Initializing random
	    srand(time(NULL));

		globalLogger.Log("This is so beautiful");
		globalLogger.Log("<Listing arguments>");
		for (int i = 0 ; i < argc ; i++)
			globalLogger.Log(argv[i]);
		globalLogger.Log("</Listing arguments>");

		//if(!Glib::thread_supported())
		//{
		//	globalLogger.Log("Initializing Glib threads", globalLogger.Verbose);
		//	Glib::thread_init();
		//}
		//else
		//{
		//	globalLogger.Log("Glib threads are not supported", globalLogger.Error);
		//	return 1;
		//}

		Gtk::Main kit(argc, argv);

		//Load the Glade file and instiate its widgets:
		Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();

		refBuilder->add_from_file("MainWindow.glade");

		//Get the GtkBuilder-instantiated dialog::
		MainWindow* pDialog = 0;
		refBuilder->get_widget_derived("window1", pDialog);
		if(pDialog)
		{
			//Start:
			kit.run(*pDialog);
		}

		delete pDialog;

		globalLogger.Log("Program closed.");
	}
	catch(std::exception& e)
	{
		globalLogger.Log(e.what(), Logger::Error);
		return 1;
	}
	catch(const Glib::FileError& ex)
	{
		std::string debugStr;
		debugStr += "FileError: ";
		debugStr += ex.what();

		globalLogger.Log(debugStr,Logger::Error);

		return 2;
	}
	catch(const Gtk::BuilderError& ex)
	{
		std::string debugStr;
		debugStr += "BuilderError: ";
		debugStr += ex.what();

		globalLogger.Log(debugStr,Logger::Error);

		return 3;
	}

	return 0;
}
